package com.zhao.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    //设置首页
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("/show/main");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/admin/index").setViewName("index");
        registry.addViewController("/admin/index.html").setViewName("index");
        registry.addViewController("/admin/add_article").setViewName("add_article");
        registry.addViewController("/admin/add_article.html").setViewName("add_article");
        registry.addViewController("/admin/add_file").setViewName("add_file");
        registry.addViewController("/admin/add_file.html").setViewName("add_file");
        registry.addViewController("/admin/data_article").setViewName("data_article");
        registry.addViewController("/admin/data_article.html").setViewName("data_article");
        registry.addViewController("/admin/data_file").setViewName("data_file");
        registry.addViewController("/admin/data_file.html").setViewName("data_file");
        registry.addViewController("/admin/data_user").setViewName("data_user");
        registry.addViewController("/admin/data_user.html").setViewName("data_user");
        registry.addViewController("/admin/update_user").setViewName("update_user");
        registry.addViewController("/admin/update_user.html").setViewName("update_user");
        registry.addViewController("/admin/update_role").setViewName("update_role");
        registry.addViewController("/admin/update_role.html").setViewName("update_role");
        registry.addViewController("/admin/data_role").setViewName("data_role");
        registry.addViewController("/admin/data_role.html").setViewName("data_role");
        registry.addViewController("/admin/add_role").setViewName("add_role");
        registry.addViewController("/admin/add_role.html").setViewName("add_role");
        registry.addViewController("/admin/data_menu").setViewName("data_menu");
        registry.addViewController("/admin/data_menu.html").setViewName("data_menu");
        registry.addViewController("/admin/update_menu").setViewName("update_menu");
        registry.addViewController("/admin/update_menu.html").setViewName("update_menu");
        registry.addViewController("/admin/add_menu").setViewName("add_menu");
        registry.addViewController("/admin/add_menu.html").setViewName("add_menu");
        registry.addViewController("/admin/add_perms").setViewName("add_perms");
        registry.addViewController("/admin/add_perms.html").setViewName("add_perms");
        registry.addViewController("/admin/icon").setViewName("icon");
        registry.addViewController("/admin/icon.html").setViewName("icon");
        registry.addViewController("/admin/add_user").setViewName("add_user");
        registry.addViewController("/admin/add_user.html").setViewName("add_user");
        registry.addViewController("/show/main").setViewName("main");
        registry.addViewController("/show/main.html").setViewName("main");
        registry.addViewController("/show/about").setViewName("about");
        registry.addViewController("/show/about.html").setViewName("about");
        registry.addViewController("/show/content").setViewName("content");
        registry.addViewController("/show/content.html").setViewName("content");
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/file/**")
                .addResourceLocations("file:"+System.getProperty("user.dir")+"/upload/file/");
        registry.addResourceHandler("/upload/Mysql/**")
                .addResourceLocations("file:"+System.getProperty("user.dir")+"/upload/Mysql/");
        registry.addResourceHandler("/upload/userimg/**")
                .addResourceLocations("file:"+System.getProperty("user.dir")+"/upload/userimg/");
        registry.addResourceHandler("/upload/ziyuan/**")
                .addResourceLocations("file:"+System.getProperty("user.dir")+"/upload/ziyuan/");
        registry.addResourceHandler("/upload/temp/**")
                .addResourceLocations("file:"+System.getProperty("user.dir")+"/upload/temp/");
    }


/*    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/login.html",
                        "/",
                        "/admin/login",
                        "/admin/toLogin",
                        "/css/**",
                        "/js/**",
                        "/images/**",
                        "/layui/**",
                        "/md/**",
                        "/module",
                        "/show/**",
                        "/show/main",
                        "/show/selfWord",
                        "/show/main.html"
                );
    }*/
}
